package com.raft.core.support;

import java.io.IOException;
import java.io.InputStream;

public interface SeekableFile {

    /**获取当前位置
     * @return
     * @throws IOException
     */
    long position() throws IOException;

    /**移动到指定位置
     * @param position
     * @throws IOException
     */
    void seek(long position) throws IOException;

    /**写入整数
     * @param i
     * @throws IOException
     */
    void writeInt(int i) throws IOException;

    /**写入长整数
     * @param l
     * @throws IOException
     */
    void writeLong(long l) throws IOException;

    /**写入字节数组
     * @param b
     * @throws IOException
     */
    void write(byte[] b) throws IOException;

    /**读取整数
     * @return
     * @throws IOException
     */
    int readInt() throws IOException;

    /**读取长整数
     * @return
     * @throws IOException
     */
    long readLong() throws IOException;

    /**读取字节数组，返回读取的长度
     * @param b
     * @return
     * @throws IOException
     */
    int read(byte[] b) throws IOException;

    /**获取文件大小
     * @return
     * @throws IOException
     */
    long size() throws IOException;

    /**裁剪到指定大小：用于在日志冲突时删除某个索引后的日志数据
     * @param size
     * @throws IOException
     */
    void truncate(long size) throws IOException;

    /**获取从指定位置开始的输入流：用于日志快照
     * @param start
     * @return
     * @throws IOException
     */
    InputStream inputStream(long start) throws IOException;

    /**强制输出到磁盘
     * @throws IOException
     */
    void flush() throws IOException;

    /**关闭文件
     * @throws IOException
     */
    void close() throws IOException;

}
